package com.javiercp.ayudaapp.preferences;

import android.os.Build;
import android.preference.PreferenceCategory;

public abstract class ContactsPreferenceDeflater {
	
	private static ContactsPreferenceDeflater mInstance;
	
	public static ContactsPreferenceDeflater getInstance() {
		if (mInstance == null) {
			String className;
			
			int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
			if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
				//TODO: verificar compatibilidad
				className = "ContactsPreferenceDeflaterSDK5";
			}
			else {
				className = "ContactsPreferenceDeflaterSDK5";
			}
			
			try {
				Class<? extends ContactsPreferenceDeflater> myClass = 
					Class.forName(ContactsPreferenceDeflater.class.getPackage().getName() + "." + className).asSubclass(ContactsPreferenceDeflater.class);
				
				mInstance = myClass.newInstance();
			} catch (Exception e) {
				throw new IllegalStateException(e);
			}
		}
		
		return mInstance;
	}
	
	public abstract String deflate(PreferenceCategory pref);
}
